import { defineStore } from 'pinia';
import { ref } from 'vue';
import axios from 'axios';

export const useMainStore = defineStore('main', () => {
  const couponCount = ref(0);
  const propCardCount = ref(0);

  const fetchData = async () => {
    try {
      const couponResponse = await axios.get('/api/coupons');
      couponCount.value = couponResponse.data.length;

      const propCardResponse = await axios.get('/api/prop-cards');
      propCardCount.value = propCardResponse.data.length;
    } catch (error) {
      console.error('获取数据失败', error);
    }
  };

  return {
    couponCount,
    propCardCount,
    fetchData,
  };
});
